# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: findfile.py 
@time: 2019/8/1 下午2:12
@note:
查找文件
"""
from os import walk
from os.path import join, normpath, abspath
from sys import argv, stderr

def findfile(start, name):

    try:
        for relpath, dirs, files in walk(start):
            fname = [x for i, x in enumerate(files) if x.find(name) != -1]
            if fname:
                for file in fname:

                    full_path = join(start, relpath, file)
                    print(normpath(abspath(full_path)))
    except RuntimeError as e:
        print(e.args)
        raise SystemExit(1)

if __name__ == '__main__':

    if len(argv) != 3:
        print(f"Usage:{argv[0]} path keyword", file=stderr)
        raise SystemExit(1)
    findfile(argv[1], argv[2])